package com.bgs.travelapp.fileManager.mapper;

import com.bgs.travelapp.mapper.BaseMapper;
import com.bgs.travelapp.scenic.entity.ScenicEntity;
import com.bgs.travelapp.fileManager.entity.FileManagerEntity;
import org.apache.ibatis.annotations.*;

public interface FileManagerMapper extends BaseMapper<ScenicEntity> {
    /**
     * 批量上传图片到数据库
     * @param fileManagerEntity
     * @return
     */
    @Insert("insert into file_manager (file_name,file_path,file_size,file_suffix,file_encryption_name,create_time,update_time,del_flag) " +
            "value (#{fileManagerEntity.fileName},#{fileManagerEntity.filePath},#{fileManagerEntity.fileSize},#{fileManagerEntity.fileSuffix},#{fileManagerEntity.fileEncryptionName}," +
            "#{fileManagerEntity.createTime},#{fileManagerEntity.updateTime},#{fileManagerEntity.del_flag})")
    @Options(useGeneratedKeys = true,keyProperty = "fileManagerEntity.id",keyColumn = "id")
    Integer saveFile(@Param("fileManagerEntity") FileManagerEntity fileManagerEntity);

    /**
     * 下载上传的附件
     * @param id
     * @return
     */
    @Select("select * from file_manager where id=#{id}")
    @Results({
            @Result(property = "fileName",column = "file_name"),
            @Result(property = "filePath",column = "file_path"),
            @Result(property = "fileSize",column = "file_size"),
            @Result(property = "fileSuffix",column = "file_suffix"),
            @Result(property = "fileEncryptionName",column = "file_encryption_name"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "updateTime",column = "update_time"),
    })
    FileManagerEntity getScenicPritureEntityById(Integer id);


    /**
     * 游记封面图片上传
     * @param fileManagerEntity
     * @return
     */
    @Insert("insert into file_manager (file_name,file_path,file_size,file_suffix,file_encryption_name,create_time,update_time,del_flag) " +
            "value (#{fileManagerEntity.fileName},#{fileManagerEntity.filePath},#{fileManagerEntity.fileSize},#{fileManagerEntity.fileSuffix},#{fileManagerEntity.fileEncryptionName}," +
            "#{fileManagerEntity.createTime},#{fileManagerEntity.updateTime},#{fileManagerEntity.del_flag})")
    @Options(useGeneratedKeys = true,keyProperty = "fileManagerEntity.id",keyColumn = "id")
    Integer saveTextFile(@Param("fileManagerEntity") FileManagerEntity fileManagerEntity);
}
